<template>
  <div class="my-app-container">
    <div class="banner"></div>

    <ul
      class="app-list"
      :class="{'center': appData.length < 5}"
    >
      <li
        v-for="item in appData"
        :key="item.id"
        @click="jumpApp(item)"
      >
        <div class="app-icon">
          <img
            src="../../assets/images/app_icon.png"
            alt="icon"
          >
        </div>
        <div class="app-info">
          <p class="app-title">{{ item.title }}</p>
          <p class="app-describe">{{ item.describe }}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { getUserRolePower } from '@/api/userRole';
export default {
  name: 'MyApp',
  data() {
    return {
      appData: []
    };
  },
  created() {
    this.getUserAuth();
    this.appData = [
      {
        id: 1,
        url: '/ams/',
        title: '应用管理',
        describe: '应用管理'
      },
      {
        id: 2,
        url: '/marketCenterApp/',
        title: '营销中心',
        describe: '营销中心'
      },
      {
        id: 3,
        url: '/systemManageApp/',
        title: '系统管理',
        describe: '系统管理'
      },
      {
        id: 4,
        url: '/deviceApp/',
        title: '设备中心',
        describe: '设备中心'
      }
    ];
  },
  methods: {
    // 获取用户权限
    getUserAuth() {
      let userInfo = JSON.parse(localStorage.getItem('userInfo'));
      let { last_customer_id } = userInfo;
      getUserRolePower({
        customer_id: last_customer_id
      }).then(res => {
        console.log('res---', res);
      });
    },
    // 应用跳转
    jumpApp(item) {
      let origin = window.location.origin;
      let href = `${origin}${item.url}`;
      window.location.href = href;
    }
  }
};
</script>

<style lang="scss" scoped>
.my-app-container {
  width: 100%;
  height: 100%;

  .banner {
    width: 100%;
    height: 300px;
    background: url('../../assets/images/banner.png') center no-repeat;
    background-size: cover;
  }

  .app-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, 256px);
    column-gap: 40px;
    row-gap: 27px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 40px 0;

    li {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 256px;
      height: 268px;
      border-radius: 10px;
      background-color: #fff;
      overflow: hidden;
      box-shadow: 0 0 8px #ebebeb;

      &:hover {
        box-shadow: 0 0 12px 2px var(--hover-primary);

        .app-title {
          color: var(--color-primay) !important;
        }
      }

      .app-icon {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 120px;
        height: 105px;
        overflow: hidden;

        img {
          width: 100%;
          object-fit: cover;
        }
      }

      .app-info {
        margin-top: 32px;
        text-align: center;

        .app-title {
          font-size: 16px;
          color: #303133;
        }

        .app-describe {
          margin-top: 12px;
          color: #909399;
        }
      }
    }
  }

  .center {
    justify-content: center;
  }
}
</style>
